package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
public class CartController {
    @Autowired
    private CartService cartService;

    // 添加购物车
    @PostMapping("/cart/add")
        public ResultInfo add(@RequestBody Cart cartParam) { // 1.接收参数
            // 2.调用service添加
            Cart cart = cartService.add(cartParam);

            // 3.返回结果
            return ResultInfo.success(cart);
    }

    @GetMapping("/cart/list")
    public ResultInfo list() {
        // 调用service查询并返回
       // List<Cart> cartList = cartService.list();
       // return ResultInfo.success(cartList);

        //合并成一步
           return ResultInfo.success(cartService.list());
    }
    @DeleteMapping("/cart/clean")
    public ResultInfo clean(){
        cartService.clean();
        return ResultInfo.success();
    }
    @PostMapping("/cart/sub")
    public ResultInfo sub(@RequestBody Cart cartParam){
        Cart cart = cartService.sub(cartParam);
        return  ResultInfo.success(cart);
    }

}
